package leetcode.l0614;

/**
 * @author Retain
 * @date 2021/6/14 19:50
 */
public class Easy_猜数字大小_374 {
    public int guessNumber(int n) {
        int left = 1;
        int right = n;
        while(left < right) {
            int mid = left + (right - left) / 2;
            if (guess(mid) == 0) {
                return mid;
            }else if (guess(mid) == 1) {
                left = mid + 1;
            }else {
                right = mid;
            }
        }
        return left;
    }

    /**
     * 题目自带函数
     * @param n
     * @return
     */
    public  int guess(int n){
        return n;
    };
}
